package conn

import (
	"easyreport/conf"
	"github.com/go-redis/redis"
)

var Redis =make(map[string]*redis.Client)

func NewRedis() {
	for k, v := range conf.Get().Redis {
		redisCli := redis.NewClient(&redis.Options{
			Addr:     v["addr"].(string),
			Password: v["password"].(string),
		})
		_, err := redisCli.Ping().Result()
		if err != nil {
			CloseRedis()
			panic("redis初始化失败！")
			return
		}
		Redis[k] = redisCli
	}
}

func CloseRedis() {
	for _, v := range Redis {
		v.Close()
	}
}
